﻿namespace _01.MobileDevice
{
    using System;

    public enum BatteryType
    {
        LiPoly,
        LiIon,
        NiCd,
        NiMH
    }

    public class Battery
    {
        private string model;
        private int? hoursIdle;
        private int? hoursTalk;

        public Battery(string model)
        {
            this.model = model;
        }

        public Battery(BatteryType type, int? hoursIdle, int? hoursTalk)
        {
            this.Type = type;
            this.HoursIdle = hoursIdle;
            this.HoursTalk = hoursTalk;
        }

        public Battery(string model, BatteryType type, int? hoursIdle, int? hoursTalk)
        {
            this.Model = model;
            this.Type = type;
            this.HoursIdle = hoursIdle;
            this.HoursTalk = hoursTalk;
        }

        public string Model
        {
            get
            {
                return this.model;
            }

            set
            {
                if (value == string.Empty)
                {
                    throw new ArgumentException("Invalid model");
                }

                this.model = value;
            }
        }

        public BatteryType Type { get; set; }

        public int? HoursIdle
        {
            get
            {
                return this.hoursIdle;
            }

            set
            {
                if (value < 0 && 9999 < value)
                {
                    throw new ArgumentOutOfRangeException();
                }
                else if (value == null)
                {
                    throw new ArgumentNullException();
                }

                this.hoursIdle = value;
            }
        }

        public int? HoursTalk
        {
            get
            {
                return this.hoursTalk;
            }

            set
            {
                if (value < 0 && 9999 < value)
                {
                    throw new ArgumentOutOfRangeException();
                }

                this.hoursTalk = value;
            }
        }

        public override string ToString()
        {
            return string.Format("Model: {0}, Type: {1}, Hours Idle: {2}, Hours Talk: {3}", this.model, this.Type, this.hoursIdle, this.hoursTalk);
        }
    }
}
